package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.TeamStaffData;
import com.topscore.uke.mvp.contractors.GetGroupStaffContractor;
import com.topscore.uke.mvp.model.GetTeamStaffModel;

/**
 * Created by 71468 on 2017/10/16.
 */

public class GetGroupStaffListPresenter implements GetGroupStaffContractor, GetGroupStaffContractor.Presenter {
    private View mView;
    private final String mGroupCode;

    private GetTeamStaffModel model;

    public GetGroupStaffListPresenter(String groupCode, View view) {
        this.mGroupCode = groupCode;
        this.mView = view;
        model = new GetTeamStaffModel(mGroupCode);
    }

    @Override
    public void getStaffList() {
        mView.onLoading("请稍等");
        model.getList(new Listener() {
            @Override
            public void onGetListSuccess(TeamStaffData data) {
//                mView.onLoadStaffListSuccess(data.getDataList());
                mView.getCaptainAdapter().setNewData(data.getCaptain());
                mView.getStaffListAdapter().setNewData(data.getDataList());
                if (data.getDataList().size() < 20) {
                    mView.getStaffListAdapter().setEnableLoadMore(false);
                    mView.getStaffListAdapter().loadMoreEnd();
                }
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode, errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void loadNextPage() {
        model.getNextPage(new Listener() {
            @Override
            public void onGetListSuccess(TeamStaffData data) {
                mView.getStaffListAdapter().addData(data.getDataList());
                if (data.getDataList().size() < 20) {
                    mView.getStaffListAdapter().setEnableLoadMore(false);
                    mView.getStaffListAdapter().loadMoreEnd();
                }
//                mView.onLoadNextPageSuccess(data.getDataList());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.getStaffListAdapter().loadMoreFail();
                mView.getStaffListAdapter().setEnableLoadMore(false);
//                mView.onLoadNextPageFailed();
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
